<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        保养工单
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="x-nav">
            <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>工单管理</cite></a>
            <a><cite>保养工单</cite></a>
        </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>

        <div class="row">
            <div class="col-xs-6 col-sm-4 col-md-3">
                <section class="panel">
                    <div class="symbol bgcolor-blue"><i class=" iconfont icon-dashaxiaoqudizhi01"></i>
                    </div>
                    <div class="value tab-menu" bind="1">
                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="今日保养"><i
                            class="iconfont " data-icon=""></i>
                        <h1>{{statistics.todaynum == null ? 0 : statistics.todaynum}}</h1>
                    </a>
                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="今日保养"> <i class="iconfont " data-icon=""></i><span>今日保养</span></a>
                    </div>
                </section>
            </div>
            <div class="col-xs-6 col-sm-4 col-md-3">
                <section class="panel">
                    <div class="symbol bgcolor-commred"><i class="iconfont icon-dashaxiaoqudizhi01"></i>
                    </div>
                    <div class="value tab-menu" bind="1">
                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="未结束保养"> <i class="iconfont " data-icon=""></i>
                            <h1>{{statistics.unDonum == null ? 0 : statistics.unDonum}}</h1>
                        </a>

                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="未结束保养"> <i class="iconfont " data-icon=""></i><span>未结束保养</span></a>
                    </div>
                </section>
            </div>
            <div class="col-xs-6 col-sm-4 col-md-3">
                <section class="panel">
                    <div class="symbol bgcolor-dark-green"><i class="iconfont icon-dashaxiaoqudizhi01"></i>
                    </div>
                    <div class="value tab-menu" bind="1">
                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="本月保养"> <i class="iconfont " data-icon=""></i>
                            <h1>{{statistics.monthnum == null ? 0 : statistics.monthnum}}</h1>
                        </a>

                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="本月保养"> <i class="iconfont " data-icon=""></i><span>本月保养</span></a>
                    </div>
                </section>
            </div>
            <div class="col-xs-6 col-sm-4 col-md-3">
                <section class="panel">
                    <div class="symbol bgcolor-orange"><i class="iconfont icon-dashaxiaoqudizhi01"></i>
                    </div>
                    <div class="value tab-menu" bind="1">
                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="上月保养"> <i class="iconfont " data-icon=""></i>
                            <h1>{{statistics.premonthnum == null ? 0 : statistics.premonthnum}}</h1>
                        </a>

                        <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="上月保养"> <i class="iconfont " data-icon=""></i><span>上月保养</span></a>
                    </div>
                </section>
            </div>

        </div>

        <div class="main_box">
            <div class="panel-heading">
                <h2>保养工单</h2>
            </div>
        </div>

        <form class="layui-form x-center">
            <div class="layui-form-pane" style="margin-top: 15px;">
                <div class="layui-form-item">
                    <div class="layui-form-item" id="area-picker">
                        <div class="layui-form-label">省市地区</div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select name="province" class="province-selector" lay-filter="province-1">
                            <option value="">请选择省</option>
                        </select>
                        </div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select name="city" class="city-selector" lay-filter="city-1">
                            <option value="">请选择市</option>
                        </select>
                        </div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select name="county" class="county-selector" lay-filter="county-1">
                            <option value="">请选择区</option>
                        </select>
                        </div>
                    </div>
                    <input  autocomplete="off" type="hidden" name="areaString" id="areaString">
                    <label class="layui-form-label">使用单位</label>
                    <div class="layui-input-inline">
                        <select name="companyId" id="companyId" lay-search="" lay-filter="brickType">
                        <option value="">请选择</option>
                    </select>

                    </div>
                    <label class="layui-form-label">项目名称</label>
                    <div class="layui-input-inline">
                        <select name="projectId" id="projectId" lay-search="">
                        <option value="">请选择</option>
                    </select>
                    </div>
                    <hr>
                    <label class="layui-form-label">工单编号</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off" type="text" class="layui-input" name="numbercode" id="numbercode" placeholder="工单编号">
                    </div>
                    <label class="layui-form-label">电梯位置</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off" type="text" class="layui-input" name="address" id="address" placeholder="电梯位置">
                    </div>
                    <label class="layui-form-label">维保人员</label>
                    <div class="layui-input-inline">
                        <select id="maintenancepersonId" name="maintenancepersonId" lay-search="">
                        <option value="">请选择</option>
                    </select>
                    </div>
                    <label class="layui-form-label">工单状态</label>
                    <div class="layui-input-inline">
                        <select id="status" name="status" lay-search="">
                        <option value="">请选择</option>
                        <option value="开始保养">开始保养</option>
                        <option value="结束保养">结束保养</option>
                        <!--<option value="已取消">已取消</option>-->

                    </select>
                    </div>
                    <hr>
                    <label class="layui-form-label">签字</label>
                    <div class="layui-input-inline">
                        <select id="propertyConfirmed" lay-search="">
                        <option value="">请选择</option>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                    </div>
                    <label class="layui-form-label">位置异常</label>
                    <div class="layui-input-inline">
                        <select id="addressAbnormal" lay-search="">
                        <option value="">请选择</option>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                    </div>

                    <label class="layui-form-label">超期</label>
                    <div class="layui-input-inline">
                        <select id="isoverdue" lay-search="">
                        <option value="">请选择</option>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                    </div>
                    <label class="layui-form-label">添加时间</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off" class="layui-input" placeholder="开始日" name="starttime" id="starttime">
                    </div>
                    <div class="layui-input-inline">
                        <input  autocomplete="off" class="layui-input" placeholder="截止日" name="endtime" id="endtime">
                    </div>
                    <div class="layui-input-inline layui-show-xs-block">
                        <button class="layui-btn" type="button" lay-filter="sreach" data-type="reload" onclick="reload()">
                        <i class="layui-icon">&#xe615;</i></button>
                    </div>

                </div>
            </div>
        </form>


        <div class="layui-card-body">

            <table class="layui-table" id="test" lay-filter="test">
            </table>
        </div>
        <br><br><br><br><br><br>
    </div>
</body>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="view">详情</a>
   <!-- <a class="layui-btn layui-btn-xs" style="background: #673ab7" lay-event="qx">取消工单</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">取消工单</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="jieshu">强制结束工单</a>
</script>


<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/myAjax.js"></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
    //配置插件目录
    layui.config({
        base: '../../js/',
        version: '1.0'
    });
</script>
<script>
    layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function() {
        $ = layui.jquery; //jquery
        laydate = layui.laydate; //日期插件
        lement = layui.element; //面包导航
        laypage = layui.laypage; //分页
        layer = layui.layer; //弹出层
        var form = layui.form;
        okLoading.close($);
    });
</script>


<script>
    layui.use(['laydate', 'form', 'layarea'],
        function() {
            var laydate = layui.laydate;
            var layarea = layui.layarea;


            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'date',
                elem: '#starttime' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'date',
                elem: '#endtime' //指定元素
            });

            layarea.render({
                elem: '#area-picker',
                // data: {
                //     province: '广东省',
                //     city: '深圳市',
                //     county: '龙岗区',
                // },
                change: function(res) {
                    //选择结果
                    console.log(res);
                    if (res.province != "") {
                        $("#areaString").val(res.province + "," + res.city + "," + res.county);
                    } else {
                        $("#areaString").val("");
                    }

                }
            });

            var form = layui.form;



            let request2 = {
                url: 'maintenance/company/findAll',
                method: "GET",
                data: {
                    userId: $userId
                }
            };
            sendRequest(request2, (res) => {
                let x = res.data;
                console.log(res.data);
                $.each(x, function(index, item) {
                    let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                    $("#companyId").append(opt);
                });
                form.render('select');

            });

            let request3 = {
                url: 'maintenance/project/findAll',
                method: "GET",
                data: {
                    userId: $userId
                }
            };
            sendRequest(request3, (res) => {
                let x = res.data;
                $.each(x, function(index, item) {
                    let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                    $("#projectId").append(opt);
                });
                form.render('select');
            });


            let request4 = {
                url: 'user/getMaintenanceUser',
                method: "GET",
                data: {
                    userId: $userId
                }
            };
            sendRequest(request4, (res) => {
                let x = res;
                $.each(x, function(index, item) {
                    let opt = $("<option value=" + item.id + ">" + item.nickname + "</option>");
                    $("#maintenancepersonId").append(opt);
                });
                form.render('select');
            });

            form.on('select(brickType)', function(data) {
                let opthtml = $("<option value=''>请选择</option>");
                $("#projectId").html(opthtml);
                form.render('select');
                var val = data.value;
                if (val != "") {
                    let request = {
                        url: 'maintenance/project/findByCompanyId',
                        data: {
                            companyId: val,
                            userId: $userId,
                        },
                        method: "POST",
                    };
                    sendRequest(request, (res) => {
                        let x = res.data;
                        $.each(x, function(index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                            $("#projectId").append(opt);
                        });
                        form.render('select');
                    });
                }

            });

        });


    layui.use('table', function() {
        table = layui.table;
        //方法级渲染
        var t1 = table.render({
            elem: '#test',
            url: $baseUrl + 'maintenance/mainOrder/list',
            where: {
                userId: $userId,
            },
            headers: {
                token: $token
            },
            toolbar: '#toolbarDemo',

            // toolbar: true,
            cols: [
                [

                    {
                        field: 'numbercode',
                        title: '工单编号',
                        fixed: 'left',
                        width: '160',
                        templet(item) {
                            return item.order.numbercode == undefined ? "" : item.order.numbercode;
                        }
                    }, {
                        field: 'companyname',
                        title: '项目名称',
                        width: '150',
                        templet(item) {
                            return item.elevator.project.name == undefined ? "" : item.elevator.project.name;
                        }
                    },

                    {
                        field: 'address',
                        title: '电梯位置',
                        width: '250',
                        templet(item) {
                            return item.elevator.address == undefined ? "" : item.elevator.address;
                        }
                    }, {
                        field: 'maintype',
                        title: '保养类型',
                        width: '100',
                        templet(item) {
                            return item.order.maintenanceType == undefined ? "" : item.order.maintenanceType;
                        }
                    }, {
                        field: 'bankAndAccountNumber',
                        title: '维保人员',
                        width: '100',
                        templet(item) {
                            var person = "";
                            $.each(item.personList, function(index, itemperson) {

                                var name = itemperson + " ";
                                person += name;
                            });
                            return person;
                        }
                    }, {
                        title: '状态',
                        width: '100',
                        templet(item) {
                            return item.order.status == undefined ? "" : item.order.status;
                        }
                    }, {
                        field: 'startTime',
                        title: ' 开始时间',
                        width: '180',
                        templet(item) {
                            return item.order.startTime == undefined ? "未开始" : item.order.startTime;
                        }
                    }, {
                        field: 'endTime',
                        title: '结束时间',
                        width: '180',
                        templet(item) {
                            return item.order.endTime == undefined ? "未结束" : item.order.endTime;
                        }

                    }, {
                        field: 'timeConsuming',
                        title: '耗时',
                        width: '100',
                        templet(item) {
                            return item.order.timeConsuming == undefined ? "暂无" : item.order.timeConsuming;
                        }

                    }, {
                        field: 'addressAbnormal',
                        title: '位置异常',
                        width: '100',
                        templet(item) {
                            return item.order.addressAbnormal == undefined ? "" : item.order.addressAbnormal;
                        }

                    },

                    {
                        field: 'associatedCredentials',
                        title: '超期',
                        width: '80',
                        templet(item) {
                            return item.order.isoverdue == undefined ? "" : item.order.isoverdue;
                        }

                    }, {
                        field: 'isWorkOrder',
                        title: '电子工单',
                        width: '100',
                        templet(item) {
                            if (item.order.isWorkOrder == 0) {
                                return "是";
                            } else {
                                return "否";
                            }
                        }
                    }, {
                        field: 'companyname',
                        title: '使用单位',
                        width: '200',
                        templet(item) {
                            return item.elevator.company.name == undefined ? "" : item.elevator.company.name;
                        }
                    }, {
                        field: 'areaString',
                        title: '省市地区',
                        width: '200',
                        templet(item) {
                            return item.elevator.project.areaString == undefined ? "" : item.elevator.project.areaString;
                        }
                    },

                    {
                        field: 'status',
                        title: '操作',
                        templet: '#barDemo',
                        fixed: 'right',
                        width: '300',
                    }
                ]
            ],
            request: {
                pageName: 'pageNum', //页码的参数名称，默认：page
                limitName: 'pageSize',
            },
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                    ,
                statusCode: 0 //规定成功的状态码，默认：0
                    ,
                msgName: 'msg' //规定状态信息的字段名称，默认：msg
                    ,
                countName: 'total' //规定数据总数的字段名称，默认：count
                    ,
                dataName: 'data', //规定数据列表的字段名称，默认：data
            },
            id: 'test',
            page: true,
            height: 'auto',
            even: true,
            done: function(res, curr, count) {
                //是否有权限或权限是否失效
                // authorizeState();
            }
        });

        //监听工具条
        table.on('tool(test)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'del') { //删除
                layer.confirm('是否确认取消这个工单 ？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    if (data.order.status == "已取消" || data.order.status == "结束维修") {
                        layer.msg("该工单已经结束，不能取消！", {
                            icon: 5
                        });
                    } else {
                        let request = {
                            url: "maintenance/mainOrder/del/" + data.order.id,
                            data: {
                                userId: $userId,
                            },
                            method: "DELETE",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.msg("删除成功", {
                                    icon: 1
                                });
                                t1.reload();
                            } else {
                                layer.msg(" ", {
                                    icon: 5
                                });
                            }
                        });
                        layer.close(index);
                    }


                });
            } else if (layEvent === 'view') { //详情
                admin_add('工单详情', 'maintain_details.html?recordId=' + data.order.id, '1400', '800')
            } /*else if (layEvent === 'qx') { //作废

                layer.confirm('是否取消工单？', {
                    icon: 3,
                    title: '提示'
                }, function(index) {
                    if (data.order.status == "已取消" || data.order.status == "结束维修") {
                        layer.msg("该工单已经结束，不能取消！", {
                            icon: 5
                        });
                    } else {
                        let request = {
                            url: "maintenance/mainOrder/cancel",
                            data: {
                                userId: $userId,
                                id: data.order.id
                            },
                            method: "POST",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.msg("取消成功", {
                                    icon: 1
                                });
                                t1.reload();
                            } else {
                                layer.msg("取消失败，请稍后再试！", {
                                    icon: 5
                                });
                            }
                        });

                    }
                    layer.close(index);
                });

            } */else if (layEvent === 'jieshu') { //强制结束工单

                layer.confirm('是否强制结束工单？', {
                    icon: 3,
                    title: '提示'
                }, function(index) {
                    if (data.order.status == "已取消" || data.order.status == "结束保养") {
                        layer.msg("该工单已经结束，不能结束！", {
                            icon: 5
                        });
                    } else {
                        let request = {
                            url: "maintenance/mainOrder/finish",
                            data: {
                                userId: $userId,
                                id: data.order.id
                            },
                            method: "POST",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.msg("强制结束成功", {
                                    icon: 1
                                });
                                t1.reload();
                            } else {
                                layer.msg("强制结束失败，请稍后再试！", {
                                    icon: 5
                                });
                            }
                        });

                    }
                    layer.close(index);
                });

            }
        });

    });

    function reload(value) {
        table.reload('test', {
            where: {
                areaString: $("#areaString").val(),
                companyId: $("#companyId").val(),
                projectId: $("#projectId").val(),
                numbercode: $("#numbercode").val(),
                address: $("#address").val(),
                maintenancepersonId: $("#maintenancepersonId").val(),
                propertyConfirmed: $("#propertyConfirmed").val(),
                addressAbnormal: $("#addressAbnormal").val(),
                isoverdue: $("#isoverdue").val(),
                starttime: $("#starttime").val(),
                endtime: $("#endtime").val(),
                status: $("#status").val(),
            }
        });
    }

    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }
</script>

<script>
    new Vue({
        el: "#app",
        data: {
            statistics: {
                todaynum: null,
                unDonum: null,
                monthnum: null,
                premonthnum: null
            }
        },
        created() {
            let form = layui.form;
            let request = {
                url: 'maintenance/mainOrder/staticdata',
                method: "POST",
                data: {
                    userId: $userId
                }
            };
            sendRequest(request, (res) => {
                this.statistics = res.data;
            });


        }
    });
</script>


</html>